package com.zxp.quartz.scheduler;

import com.zxp.quartz.jdktimer.Task;

import java.util.TimerTask;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @author zxp
 * @date 2021-09-01 8:51
 */
public class SchedulePoolThreadTest {
    public static void main(String[] args) {
        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(2);

        // 1秒后执行一次
        //scheduledExecutorService.schedule(new Task("schedule任务"), 1L, TimeUnit.SECONDS);

        // 间隔0秒后， 每2秒执行, 单任务
        //scheduledExecutorService.scheduleAtFixedRate(new Task("任务2"), 0, 2, TimeUnit.SECONDS);

        // 任务间隔是2秒，任务执行了3秒，造成了任务间隔失效，紧接着执行下一个任务
        for (int i = 0; i < 2; i++) {
            scheduledExecutorService.scheduleAtFixedRate(new Task("任务"+i), 0, 2, TimeUnit.SECONDS);
        }


    }
}
